package com.cash.app.ui.main.model

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.cash.app.base.BaseViewModel
import com.cash.app.constant.AppConstant
import com.cash.app.manager.GlobalTaskManager
import com.cash.app.manager.api.GlobalAPIService
import com.cash.app.manager.model.VipProductResponse
import com.cash.app.net.NetRequestExecutor
import com.cash.app.net.RetrofitClient
import com.cash.app.utils.SpUtils
import com.cash.app.utils.TLog

class MainViewModel : BaseViewModel() {

    private val globalAPIService by lazy {
        RetrofitClient.createService(GlobalAPIService::class.java)
    }

    private val _vipProduct = MutableLiveData<VipProductResponse>()
    val vipProduct: LiveData<VipProductResponse> = _vipProduct


    fun getAccountInfo() {
        GlobalTaskManager.getAccountDetail()
    }

    fun getVipProduct() {
        if (!SpUtils.get(AppConstant.K_APP_LOGIN, false)) {
            TLog.d("getVipProduct need login","MainViewModel")
            return
        }
        launchRequest(request = {
            NetRequestExecutor.baseNetRequest {
                globalAPIService.getVipProduct()
            }
        }, onSuccess = { response ->
            response?.let {
                _vipProduct.value = it
            }
        })
    }
}